package com.ys.day31.p3FastJson;

import com.alibaba.fastjson.JSON;

import java.io.*;
import java.lang.reflect.Field;
import java.util.List;

/**
 * 描述: 将远程服务器复杂的JSON对象转换为Java对象
 * * 远程服务器复杂JSON对象转换为Java对象
 * * 步骤：1根据JSON对象进行建模(Car Course  Student)
 * *       2 远程JSON对象数据下载到本地
 * *       3 将JSON对象转换为Java对象Student
 * *       4 打印Java对象Student
 *
 * @author CodeYang
 * @version 2021/1/18 23:46
 */
public class P2FastJsonTest2 {

    private static final String URL_PATH = "https://douhuvillage.cn/json/json.json";

    public static void main(String[] args) throws Exception {


        try {
//            String jsonData = JSONUtils.downJsonData(URL_PATH); etc\jsonstr.json
            // 因为远程访问有问题,我们从本地来读
            FileInputStream inputStream = new FileInputStream("day_31/etc/jsonstr.json");
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));


            String len = null;
            String jsonStr = "";
            while ((len = reader.readLine())!=null){
                jsonStr+=len;
            }

            System.out.println(jsonStr);

            List<Student> list = JSON.parseArray(jsonStr, Student.class);
            for (Student student : list) {
                System.out.println(student);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
